<?php include_once "wish_top.php";
$where='1';
$stime=$_GET['sdate']?strtotime($_GET['sdate']):strtotime(date('Y-m-d',time()));
$etime=$_GET['edate']?(strtotime($_GET['edate'])+86400):(strtotime(date('Y-m-d',time()))+86400);
$where.=$_GET['status']?(' and status = '.$_GET['status']):(' and status > 0');
$where.=(' and create_time >= '.$stime.' and create_time < '.$etime);
$where.=' order by id asc';
?>
<div class="addleft">
	<a href="wish_list.php">心愿单执行列表</a>
</div>
<div class="addbar">
	<ul>
	<h2 style="float:left">心愿单执行列表</h2>
	<div style="float:left;margin:20px 0 0 20px">
		<form action="wish_list.php" method="get" onsubmit="return checkForm()">
		<input id="sdate" type="text" name="sdate" value="<?php echo $_GET['sdate']?$_GET['sdate']:date('Y-m-d',time())?>" class="laydate-icon ipt" onclick="laydate()" placeholder="选择开始日期" style="width:150px" /> -
		<input id="edate" type="text" name="edate" value="<?php echo $_GET['edate']?$_GET['edate']:date('Y-m-d',time())?>" class="laydate-icon ipt" onclick="laydate()" placeholder="选择结束日期" style="width:150px" />
		<select name="status" class="ipt" style="width:auto;height:24px">
			<option value="0"<?php echo $_GET['status']==0?' selected':''?>>全部</option>
			<option value="1"<?php echo $_GET['status']==1?' selected':''?>>未实现</option>
			<option value="2"<?php echo $_GET['status']==2?' selected':''?>>已实现</option>
			<option value="3"<?php echo $_GET['status']==3?' selected':''?>>已评价</option>
		</select>
		<input type="submit" name="sub_sch" value="查找" />
		<input type="button" name="" value="重置" onclick="location='wish_list.php'" />
		<input type="button" name="" value="一键导出" onclick="location='excel2.php?t=11<?php echo $_SERVER["QUERY_STRING"]?('&'.$_SERVER["QUERY_STRING"]):''?>'" />
		</form>
	</div>
	<li class="lihd"><strong align="center">
		<label style="width:120px">日期</label>
		<label style="width:120px">城市</label>
		<label style="width:120px">姓名</label>
		<label style="width:350px">内容</label>
		<label style="width:120px">状态</label>
		<label>操作</label>
		</strong>
	</li>
	<?php 
	foreach($db->ig2_select('mae_wish_list',$where) as $list){
		$user=$db->ig2_want('mae_user','id='.$list['uid']);
		$role=$db->ig2_want('mae_role','uid='.$list['uid']);
		$shop=$db->ig2_want('mae_shop','id='.$role['shop_id']);
		$city=$db->ig2_want('mae_city','id='.$shop['city_id']);
	?>
	<li align="center">
		<label style="width:120px"><?php echo date('Y-m-d',$list['create_time'])?></label>
		<label style="width:120px"><?php echo $city?$city['name']:'该用户已被删除'?></label>
		<label style="width:120px"><?php echo $user?$user['name']:'该用户已被删除'?></label>
		<label style="width:350px"><?php echo trim($list['content'])?$list['content']:'-'?></label>
		<label style="width:120px" id="status_<?php echo $list['id']?>"><?php switch($list['status']){
			case 1 : echo '未实现'; break;
			case 2 : echo '已实现(待评价)'; break;
			case 3 : echo '已评价'; break;
			default : break;
		}?></label>
		<label id="operation_<?php echo $list['id']?>"><?php switch($list['status']){
			case 1 : echo '<a href="javascript:void(0)" onclick="realizeDesire(\''.$list['id'].'\')">已实现</a>'; break;
			case 2 : echo '-'; break;
			case 3 : echo '<a href="wish_evaluate.php?id='.$list['id'].'">查看评价</a>'; break;
			default : break;
		}?></label>
	</li>
	<?php }?>
	</ul>
</div>
<script language="javascript">
function realizeDesire(id){
	if(confirm('请确认该愿望是否实现')){
		$.ajax({
			type: "GET",
			url: "ra_ajax.php?update_wish=1&id="+id,
			success: function(data){
				if(data=='success'){
					$('#status_'+id).html('已实现(待评价)');
					$('#operation_'+id).html('-');
				}
			}
		});
	}
}
function trim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function checkForm(){
	var sdate=trim($('#sdate').val());
	var edate=trim($('#edate').val());
	if(sdate!='' && edate==''){
		alert('请选择结束日期');
		return false;
	}
	if(edate!='' && sdate==''){
		alert('请选择开始日期');
		return false;
	}
	return true;
}
</script>
<?php include_once "down.php";?>